package com.bestcem.xm.ticket.entity.mongo;

import com.bestcem.xm.ticket.constant.ColumnConstant;
import com.bestcem.xm.ticket.enums.TicketFlowMatchConditionEnum;
import com.bestcem.xm.ticket.enums.TicketFlowStatusEnum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.io.Serializable;
import java.util.List;

/**
 * 工单规则跟进处理人配置记录
 * 问卷项目->开启提醒->工单规则->具体工单规则->跟进处理->通知且跟进->设置处理人
 * 一个工单规则配置对应一条跟进处理人配置, 多个跟进人的信息都存在 followConfig 列表里
 *
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/10 16:13
 */
@ToString(callSuper = true)
@Getter
@Setter
public class TicketFlow extends BaseEntity {

    private static final long serialVersionUID = -7253778583948098509L;

    /**
     * orgId
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.ORG_ID)
    private String orgId;

    /**
     * userId
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.USER_ID)
    private String userId;

    /**
     * ticketConfigId
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.TICKET_CONFIG_ID)
    private String ticketConfigId;

    /**
     * flowId 工单流程序列号
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.FLOW_ID)
    private Integer flowId;

    /**
     * title
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.TITLE)
    private String title;

    /**
     * status
     *
     * @see TicketFlowStatusEnum
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.STATUS)
    private Integer status;

    /**
     * matchCondition
     *
     * @see TicketFlowMatchConditionEnum
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.MATCH_CONDITION)
    private Integer matchCondition;

    /**
     * alertRuleIds ObjectId 数组
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.ALERT_RULE_IDS)
    private List<String> alertRuleIds;

    /**
     * customRuleIds
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.CUSTOM_RULE_IDS)
    private List<CustomRuleId> customRuleIds;

    /**
     * priority 工单流程的优先级 数字越小优先级越高
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.PRIORITY)
    private Integer priority;

    /**
     * 保存每个跟进人的详细配置, 注意数组内元素的顺序, 第一个元素就是第一跟进人, 第二个就是第二跟进人, 最多两个跟进人
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.FOLLOW_CONFIG)
    private List<FollowConfig> followConfig;

    /**
     * 工单是否需要审核
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.NEED_AUDIT)
    private Boolean needAudit;

    /**
     * auditConfig
     * <p>
     * 这个字段我不知道怎么写, python里面是 dict 类型, 但是库里没有数据, 所以我不知道到底是个什么样子
     * 沟通记录: @赵明: 这个是历史字段，现在不用了，历史数据是什么样的我也不知道
     * 补充: @刘广云: 复制样类代码显示它是FollowConfig类型
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.AUDIT_CONFIG)
    private List<FollowConfig> auditConfig;

    /**
     * version
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.VERSION)
    private Integer version;

    /**
     * 工单流程规则列表
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.RULE_LIST)
    private List<String> ruleList;

    /**
     * 是否sample
     */
    @JsonProperty(value = ColumnConstant.TicketFlow.SAMPLE)
    private Boolean sample;


    /**
     * CustomRuleId
     *
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @version v1.0
     * @date 2021/8/10 18:03
     */
    @NoArgsConstructor
    @AllArgsConstructor
    @Data
    public static class CustomRuleId implements Serializable {
        private static final long serialVersionUID = 2808726620840986656L;

        /**
         * id
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.CustomRuleId.ID)
        private String id;

        /**
         * title
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.CustomRuleId.TITLE)
        private String title;
    }

    /**
     * FollowConfig
     *
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @version v1.0
     * @date 2021/8/10 18:03
     */
    @NoArgsConstructor
    @AllArgsConstructor
    @Data
    public static class FollowConfig implements Serializable {
        private static final long serialVersionUID = 2808726620840986656L;

        /**
         * title
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.TITLE)
        private String title;

        /**
         * follower_email
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.FOLLOWER_EMAIL)
        private String followerEmail;

        /**
         * follower_id
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.FOLLOWER_ID)
        private String followerId;

        /**
         * follower_name
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.FOLLOWER_NAME)
        private String followerName;

        /**
         * 用户过滤 0-按层级过滤，1-按用户过滤
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.FOLLOWER_FILTER)
        private Integer followerFilter;

        /**
         * region
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.REGION)
        private String region;

        /**
         * roleId
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.ROLE_ID)
        private String roleId;

        /**
         * 跟进时间单位，1-小时，2-天
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.TIME_LIMIT_TYPE)
        private Integer timeLimitType;

        /**
         * 跟进时间数量，单位，小时/天
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.TIME_LIMIT)
        private String timeLimit;

        /**
         * overdueHandle
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.OVERDUE_HANDLE)
        private Integer overdueHandle;

        /**
         * 跟进人为空时处理逻辑，0-关闭工单,1-转交第二跟进人处理，2-转交给企业管理员
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.EMPTY_FOLLOWER_HANDLE)
        private Integer emptyFollowerHandle;

        /**
         * options
         */
        @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.OPTIONS)
        private List<Option> options;


        @NoArgsConstructor
        @AllArgsConstructor
        @Data
        public static class Option implements Serializable {
            private static final long serialVersionUID = 2808726620840986656L;

            /**
             * id
             */
            @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.Option.ID)
            private String id;

            /**
             * title
             */
            @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.Option.TITLE)
            private String title;

            /**
             * role_index
             */
            @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.Option.ROLE_INDEX)
            private String roleIndex;

            /**
             * roleType
             */
            @JsonProperty(value = ColumnConstant.TicketFlow.FollowConfig.Option.ROLE_TYPE)
            private Integer roleType;
        }
    }
}
